home *** CD-ROM | disk | FTP | other *** search
/ PC Graphics Unleashed / PC Graphics Unleashed.iso / ch01 / video7.asm < prev    next >
Assembly Source File  |  1991-03-20  |  4KB  |  236 lines

  1. ; This is file VIDEO7.ASM
  2. ;
  3. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. ;
  5. ; This file is distributed under the terms listed in the document
  6. ; "copying.dj", available from DJ Delorie at the address above.
  7. ; A copy of "copying.dj" should accompany this file; if not, a copy
  8. ; should be available from where this file was obtained.  This file
  9. ; may not be distributed without a verbatim copy of "copying.dj".
  10. ;
  11. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. ;
  14.  
  15. cseg    segment    byte public 'code'
  16.     assume    cs:cseg, ds:cseg, es:cseg, ss:nothing
  17.  
  18.     dw    offset init_routine
  19.     dw    offset paging_routine
  20.     dw    0    ; set to 1 if separate read & write windows or
  21.             ; only 64K of video RAM (ie: no paging)
  22.  
  23. def_tw    dw    80    ; filled in by go32 if GO32 env. var. is set
  24. def_th    dw    25
  25. def_gw    dw    640
  26. def_gh    dw    480
  27.  
  28. ;--------------------------------------------------------------------------
  29. ; Entry: AX=mode selection
  30. ;        0=80x25 text
  31. ;        1=default text
  32. ;        2=text CX cols by DX rows
  33. ;        3=biggest text
  34. ;        4=320x200 graphics
  35. ;        5=default graphics
  36. ;        6=graphics CX width by DX height
  37. ;        7=biggest non-interlaced graphics
  38. ;        8=biggest graphics
  39. ;
  40. ; NOTE: This runs in real mode, but don't mess with the segment registers.
  41. ;
  42. ; Exit:  CX=width (in pixels or characters)
  43. ;        DX=height
  44.  
  45. init_table    label    word
  46.     dw    offset init_0
  47.     dw    offset init_1
  48.     dw    offset init_2
  49.     dw    offset init_3
  50.     dw    offset init_4
  51.     dw    offset init_5
  52.     dw    offset init_6
  53.     dw    offset init_7
  54.     dw    offset init_8
  55.  
  56. init_routine    proc    far
  57.     cmp    ax,8
  58.     jbe    valid_req
  59.     ret
  60. valid_req:
  61.     shl    ax,1
  62.     mov    bx,ax
  63.     jmp    init_table[bx]
  64.  
  65. init_0: ; 80x25 text
  66.     mov    ax,3
  67.     int    10h
  68.     mov    cx,80
  69.     mov    dx,25
  70.     ret
  71.  
  72. init_1: ; default text
  73.     mov    cx,def_tw
  74.     mov    dx,def_th
  75.     jmp    init_2
  76.  
  77. init_2_table    label    word
  78.     dw    01h, 40, 25
  79.     dw    03h, 80, 25
  80. init_2_tend    label    word
  81.  
  82. init_2: ; CX*DX text
  83.     mov    si,offset init_2_table
  84. init_2a:
  85.     cmp    [si+2],cx
  86.     jb    init_2b
  87.     cmp    [si+4],dx
  88.     jb    init_2b
  89.     ; got a big enough one!
  90.     jmp    init_2c
  91. init_2b:
  92.     cmp    si,offset init_2_tend - 6
  93.     je    init_2c
  94.     add    si,6
  95.     jmp    init_2a
  96. init_2c:
  97.     mov    ax,[si]
  98.     push    si
  99.     int    10h
  100.     pop    si
  101.     mov    cx,[si+2]
  102.     mov    dx,[si+4]
  103.     ret
  104.  
  105. init_3: ; biggest text
  106.     mov    ax,[init_2_tend-6]
  107.     int    10h
  108.     mov    cx,[init_2_tend-4]
  109.     mov    dx,[init_2_tend-2]
  110.     ret
  111.  
  112. init_4: ; 320x200 graphics
  113.     mov    ax,13h
  114.     int    10h
  115.     mov    cx,320
  116.     mov    dx,200
  117.     ret
  118.  
  119. init_5: ; default graphics - should be 640x480 if supported
  120.     mov    cx,def_gw
  121.     mov    dx,def_gh
  122.     jmp    init_6
  123.  
  124. init_6_table    label    word
  125.     dw    13h, 320, 200
  126.     dw    66h, 640, 400
  127.     dw    67h, 640, 480
  128.     dw    68h, 720, 540
  129.     dw    69h, 800, 600
  130. init_6_tend    label    word
  131.  
  132. init_6: ; CX*DX graphics
  133.     mov    si,offset init_6_table
  134. init_6a:
  135.     cmp    [si+2],cx
  136.     jb    init_6b
  137.     cmp    [si+4],dx
  138.     jb    init_6b
  139.     ; got a big enough one!
  140.     jmp    init_6c
  141. init_6b:
  142.     cmp    si,offset init_6_tend - 6
  143.     je    init_6c
  144.     add    si,6
  145.     jmp    init_6a
  146. init_6c:
  147.     mov    ax,[si]
  148.     push    si
  149.     cmp    ax,13h
  150.     je    usual_way
  151.     mov    bx,ax
  152.     mov    ax,6f05h
  153. usual_way:
  154.     int    10h
  155.     pop    si
  156.     mov    cx,[si+2]
  157.     mov    dx,[si+4]
  158.     ret
  159.  
  160. init_7: ; biggest non-interlaced graphics
  161.     mov    ax,6f05h
  162.     mov    bl,69h
  163.     int    10h
  164.     mov    cx,800
  165.     mov    dx,600
  166.     ret
  167.  
  168. init_8: ; biggest graphics
  169.     mov    ax,6f05h
  170.     mov    bl,69h
  171.     int    10h
  172.     mov    cx,800
  173.     mov    dx,600
  174.     ret
  175.  
  176. init_routine    endp
  177.  
  178. ;--------------------------------------------------------------------------
  179. ; Entry: AH=read page
  180. ;        AL=write page
  181. ;
  182. ; NOTE: This runs in protected mode!  Don't mess with the segment registers!
  183. ; This code must be relocatable and may not reference any data!
  184. ;
  185. ; Exit: VGA configured.
  186. ;       AX,BX,CX,DX,SI,DI may be trashed
  187. ;
  188. ; Code derived from VGAKIT Version 3.4
  189. ;    Copyright 1988,89,90 John Bridges
  190.  
  191.     assume    ds:nothing, es:nothing
  192.  
  193. paging_routine    proc    far
  194.     and    ax,15
  195.     mov    ch,al
  196.     mov    dx,3c4h
  197.     mov    ax,0ea06h
  198.     out    dx,ax
  199.     mov    ah,ch
  200.     and    ah,1
  201.     mov    al,0f9h
  202.     out    dx,ax
  203.     mov    al,ch
  204.     and    al,1100b
  205.     mov    ah,al
  206.     shr    ah,1
  207.     shr    ah,1
  208.     or    ah,al
  209.     mov    al,0f6h
  210.     out    dx,al
  211.     inc    dx
  212.     in    al,dx
  213.     dec    dx
  214.     and    al,not 1111b
  215.     or    ah,al
  216.     mov    al,0f6h
  217.     out    dx,ax
  218.     mov    ah,ch
  219.     mov    cl,4
  220.     shl    ah,cl
  221.     and    ah,100000b
  222.     mov    dl,0cch
  223.     in    al,dx
  224.     mov    dl,0c2h
  225.     and    al,not 100000b
  226.     or    al,ah
  227.     out    dx,al
  228.  
  229.     ret
  230. paging_routine    endp
  231.  
  232. ;--------------------------------------------------------------------------
  233.  
  234. cseg    ends
  235.     end
  236.